﻿using System;
using System.Reflection;
using Microsoft.Win32;

namespace WatiNCF.Helpers
{
    public static class RegistryHelper
    {
        public static string GetRegistryOverride(string companyName, string version, string urlKeyName)
        {
            return GetRegistryOverride("SOFTWARE", companyName, version, urlKeyName);
        }

        public static string GetRegistryOverride(string localMachineRoot, string companyName, string version, string urlKeyName)
        {
            string registryValue = null;
            RegistryKey registry = Registry.LocalMachine.OpenSubKey(localMachineRoot);
            if (registry != null)
            {
                RegistryKey subKey = registry.OpenSubKey(companyName);
                if (subKey != null)
                {
                    RegistryKey versionKey = subKey.OpenSubKey(version);
                    if (versionKey != null)
                    {
                        registryValue = (string) versionKey.GetValue(urlKeyName, string.Empty);
                    }
                }
            }
            return registryValue;
        }
    }
}